import random


class Router:
    def db_for_read(self, model, **hints):
        """读"""
        ret = random.choice(["default", "slave"])
        print(ret)
        return ret  # 随机选择一个数据库进行读取操作

    def db_for_write(self, model, **hints):
        """写"""
        return "default"

    def allow_relation(self, obj1, obj2, **hints):
        """是否运行关联操作"""
        return True


